package com.itchen.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author げっしょく
 * @date 2021/9/13
 */

@Component
@Aspect
public class AopAdvice {

    @Pointcut("execution(void com.itchen.dao.BookDao.*(*,*))")
    public void pf() {
    }


    //@Before("pf()")
    public void method() {
        System.out.println("充值办卡");
    }

    //@Around("pf()")
    public Object adv(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("wuhu");
        Object proceed = pjp.proceed();

        return proceed;
    }

    @Around("pf()")
    public Object stu(ProceedingJoinPoint pjp) throws Throwable {
        Object[] args = pjp.getArgs();

        for (int i = 0; i < args.length; i++) {
            if (args[i].getClass().equals(String.class)) {
                args[i] = args[i].toString().trim();
            }
        }

        Object proceed = pjp.proceed(args);
        return proceed;
    }
}
